
//食谱列表
function loadfoodlist(pagenum,listid,apptype) {

    var xhr = new XMLHttpRequest();
    var url="http://api.9smart.cn/apps?system=belle&page="+pagenum
    if(listid != "2333"){
        url += "&id="+listid
    }
    if(apptype == "hot"){
        url+= "&order=views"
    }else{
        url+= "&type="+apptype
    }
     showfoodpage.apptype =apptype;
    xhr.open("GET",url,true);
    xhr.onreadystatechange = function()
    {
        if ( xhr.readyState == xhr.DONE)
        {
            if ( xhr.status == 200)
            {
                var jsonObject = eval('(' + xhr.responseText + ')');

                loaded(jsonObject)
            }
        }
    }

    xhr.send();
}



function loaded(jsonObject)
{
    var count=0;
    if(parseInt(jsonObject.pager.count)  == 0 ){
        header.title="无结果"
    }
    else{

        for ( var i in jsonObject.apps   )
        {

            foodlistModel.append({
                                     "appid":jsonObject.apps[i].appid,
                                     "appname":jsonObject.apps[i].appname,
                                     "icon":jsonObject.apps[i].icon,
                                     "dateline":js_date_time(jsonObject.apps[i].dateline),
                                     "summary":jsonObject.apps[i].summary,
                                     "version":jsonObject.apps[i].version,
                                     "author":jsonObject.apps[i].author,
                                     "views":jsonObject.apps[i].views,
                                     "downloads":jsonObject.apps[i].downloads,
                                     "category":jsonObject.apps[i].category
                                 });

            count +=1;
        }

    }
    progress.visible=false
    if(parseInt(count) >3){
        showfoodpage.display = true;
    }else if(parseInt(count)  ==0 ){
        showfoodpage.display = false;
        header.title="无结果"
    }
    else{
        showfoodpage.display = false;
    }
}

/**
  *parse time
  */
function js_date_time(unixtime) {
    var timestr = new Date(parseInt(unixtime) * 1000);
    var datetime = timestr.toLocaleDateString();
    return datetime;
}
